<?php
/*
 * @Author: your name
 * @Date: 2021-11-02 19:06:50
 * @LastEditTime: 2021-12-13 13:58:37
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Models/admin_model/Admin.php
 */

namespace App\Models\admin_model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Area extends Model
{
    use HasFactory;
    static string $tableName = 'area';
    
    public static function areaListSon($idStr){
        return DB::select("SELECT * FROM `area` WHERE `delete_time` is null AND `pid` IN  (".$idStr.") ORDER BY `sort` DESC,`id` DESC " );
    }
    public static function areaList($pid,$limitStr = "", $wherePidStr = ""){
        return DB::select("SELECT * FROM `area` WHERE `delete_time` is null AND  `pid` =   ".$pid.$wherePidStr." ORDER BY `sort` DESC,`id` DESC   ".$limitStr );
    }
    public static function areaCount($pid = 0,$wherePidStr = ""){
        return DB::select('SELECT COUNT(*) as `count` FROM '.self::$tableName.' WHERE `delete_time` is null AND `pid` ='.$pid.$wherePidStr);
    }

    public static function areaListSonZero($whereSonStr){
        return DB::select("SELECT * FROM `area` WHERE `delete_time` is null AND `pid` != 0 ".$whereSonStr."  ORDER BY `sort` DESC,`id` DESC " );
    }

    public static function areaListInId($idStr,$limitStr = "",$wherePidStr = ""){
        return DB::select("SELECT * FROM `area` WHERE `delete_time` is null AND id IN (".$idStr.") ".$wherePidStr." ORDER BY `sort` DESC,`id` DESC ".$limitStr);
    }

    public static function areaListInCount($idStr,$wherePidStr=""){
        return  DB::select("SELECT COUNT(*) as `count` FROM `area` WHERE `delete_time` is null AND id IN (".$idStr.") ".$wherePidStr."") ;
    }

    public static function areaListSelList($field = '*'){
        // echo " SELECT ".$field." FROM  `area` WHERE `delete_time` is null AND `status` = 1 ORDER BY `sort` DESC,`id` DESC  ";
        return DB::select(" SELECT ".$field." FROM  `area` WHERE `delete_time` is null AND `status` = 1 ORDER BY `sort` DESC,`id` DESC  ");
    }

    // public static function areaListSelListWeb(){
        // return DB::select(" SELECT * FROM  `area` WHERE `delete_time` is null AND `status` = 1 ORDER BY `sort` DESC,`id` DESC  ");
    // }

    
    
   
}
